{include file="public/nheader" /}
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="cateid">
                                <option value="">商品分类</option>
                                {foreach $class as $v}
                                <option value="{$v.id}" {if !empty(input('get.cateid')) &&
                                    input('get.cateid')==$v.id}selected{/if}>{$v.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="puton">
                                <option value="">上架类型</option>
                                <option value="1" {if !empty(input('get.puton')) && input('get.puton')==1}selected{/if}>
                                    上架</option>
                                <option value="2" {if !empty(input('get.puton')) && input('get.puton')==2}selected{/if}>
                                    下架</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="title" class="layui-input" type="text" placeholder="产品名称" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit><i
                                class="layui-icon layui-icon-search"></i>搜索</button>
                        <!-- // 打开添加页面 -->
                        <button class="layui-btn icon-btn" lay-maxmin="true" lay-open="" data-title="添加"
                            data-area="60%,80%" data-url="/shop/goods_add">添加
                        </button>
                        <!-- // 删除所有 -->
                        <button class="layui-btn icon-btn layui-btn-danger" lay-batch="lay-tableList"
                            data-url="/shop/goods_del">批量删除
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>
<script type="text/html" id="columnStatus">
    <input type="checkbox" lay-filter="switchStatus" data-url="/shop/goods_status?id={{d.id}}&field=puton" lay-skin="switch"
    {{d.puton==1?'checked':''}}   lay-text="显示|隐藏"   />
</script>
<script type="text/html" id="columnIshot">
    <input type="checkbox" lay-filter="switchStatus" data-url="/shop/goods_status?id={{d.id}}&field=ishot" lay-skin="switch"
    {{d.ishot==2?'checked':''}}   lay-text="热门|正常"   />
</script>
<!-- // 列表工具栏 -->
<script type="text/html" id="tableBar">
    <a class="layui-table-text" lay-open data-title="编辑" data-area="60%,80%" data-url="/shop/goods_add?id={{d.id}}" >编辑</a>
    <div class="layui-divider layui-divider-vertical"></div>
<a class="layui-table-text" data-url="/shop/goods_del?id={{d.id}}" lay-event="del">删除</a>
</script>
{include file="public/nfooter"}
<script>
    layui.use(['table'], function () {
        var table = layui.table;
        /*
         * 初始化表格
        */
        var isTable = table.render({
            elem: "#lay-tableList"
            , url: "{:url()}"
            , page: true
            , size: 'lg'
            , even: true
            , cols: [[
                { type: 'checkbox', width: 60 },
                { field: 'id', align: 'center', sort: true, width: 80, title: 'ID' },
                { field: 'title', align: 'center', width: 120, title: '产品名称' },
                { field: 'classname', width: 150, align: 'center', title: '分类' },
                { field: 'sku', width: 150, align: 'center', title: '库存' },
                {
                    field: 'price', align: 'center', width: 250, title: '兑换价格', templet: function (d) {
                        var text = '';
                        if (d.price > 0) {
                            text += d.price + '元';
                        }
                        if (d.price > 0 && d.intergral > 0) {
                            text += '+';
                        }
                        if (d.intergral > 0) {
                            text += d.intergral + '积分';
                        }
                        return text;
                    }
                },
                {
                    field: 'images', width: 200, align: 'center', title: '产品图片', templet: function (d) {
                        var str = '';
                        $.each(d.images, function (i, obj) {
                            str += '<img lay-image-click="" style="width:50px;" src="' + obj;
                            str += '"/>';
                        });
                        return str;
                    }
                },
                { field: 'isshow', align: 'center', width: 120, templet: '#columnStatus', title: '状态' },
                { field: 'isshow', align: 'center', width: 120, templet: '#columnIshot', title: '热门' },
                { field: 'created', width: 200, align: 'center', title: '添加时间' },
                { align: 'center', toolbar: '#tableBar', width: 200, title: '操作' },
            ]]
        })
    })
</script>
</body>